#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;
void swap(int& x, int& y)
{
    int tmp = x;
    x = y;
    y = tmp;
}
int getmid(int* arr, int left, int right)
{
    int mid = (left + right) / 2;
    if (arr[left] > arr[right])
    {
        if (arr[right] > arr[mid])
        {
            return arr[right];
        }
    }
    else
    {
        if (arr[left] > arr[mid])
        {
            return arr[left];
        }
    }
    return arr[mid];
}
void quikesort(int* arr, int left, int right)
{
    if (right <= left)
    {
        return;
    }
    int mid = getmid(arr, left, right);
    int begin = left-1;
    int end = right+1;
    while (begin < end)
    {
       /* while (arr[begin] < mid && begin < end)
        {
            begin++;
        }
        while (arr[end] > mid && begin < end)
        {
            end--;
        }*/
        do
        {
            begin++;
        } while (arr[begin] < arr[mid]);
        do
        {
            end--;
        } while (arr[end] > arr[mid]);
        if(end>begin)
        swap(arr[end], arr[begin]);

    }
   // swap(arr[left], arr[end]);
    quikesort(arr, left, begin - 1);
    quikesort(arr, begin+1, right);
}
void quick_sort_hoare(int* arr, int left, int right)
{
    if (left >= right)
    {
        return;
    }
    int begin = left;
    int end = right;
    int keyi = left;
    while (end > begin)
    {
        while (arr[end] > arr[keyi])
        {
            end--;
        }
        while (arr[begin] < arr[keyi])
        {
            begin++;
        }
        swap(arr[end], arr[begin]);
    }
    swap(arr[keyi], arr[end]);
    quick_sort_hoare(arr, 0, keyi - 1);
    quick_sort_hoare(arr, keyi + 1, right);
}
int main()
{
    int n;
    cin >> n;
    int* arr = new int[n];
    int i = 0;
    for (i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    quikesort(arr, 0, n - 1);
    for (i = 0; i < n; i++)
    {
        cout << arr[i] << " ";
    }
    return 0;
}